package org.nf.trading.controller.app.address;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nf.trading.controller.BaseController;
import org.nf.trading.entity.Address;
import org.nf.trading.service.app.address.AddressService;
import org.nf.trading.vo.ResultVO;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/api/address")
@RequiredArgsConstructor
@CrossOrigin
public class AddressController extends BaseController {
    private final AddressService addressService;

    /**
     * 添加地址信息
     * @param address
     * @return
     */
    @PostMapping
    public ResultVO saveAddress(@RequestBody Address address) {
        return success(addressService.insert(address));
    }

    /**
     * 通过用户id查询全部地址
     * @param uid
     * @return
     */
    @GetMapping("/uid/{uid}")
    public ResultVO listAddressesByUid(@PathVariable("uid") Integer uid) {
        List<Address> addresses = addressService.listAddressByUid(uid);
        return success(addresses);
    }

    /**
     * 通过id查询地址信息
     * @param addressId
     * @return
     */
    @GetMapping("{addressId}")
    public ResultVO getAddressById(@PathVariable("addressId") Integer addressId){
        Address address = addressService.selectByPrimaryKey(addressId);
        return success(address);
    }
}
